package com.atguigu.vod.controller;

import com.atguigu.commonutils.R;
import com.atguigu.vod.service.VodService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author He Wentao
 * @since 2022/9/6 20:54
 */

@RestController
@RequestMapping("eduvod/video")
public class VodController {
    @Resource
    private VodService service;


    // 上传视频方法
    @PostMapping("uploadAliyunVideo")
    public R upload(@RequestParam("file") MultipartFile filter) {

        String fileName = filter.getOriginalFilename();

        assert fileName != null;

        // 去除 文件后缀，如： .mp4 .mp3
        String title = fileName.substring(0, fileName.lastIndexOf("."));

        return service.uploadVideoAly(filter, title, fileName);

    }

    // 根据视频 id，进行删除阿里视频点播中的视频
    @DeleteMapping("removeAlyVideo/{VodId}")
    public R delete(@PathVariable("VodId") String id) {
        return service.deleteVideoById(id);
    }

    // 根据传递过来的多个 id，进行删除
    @DeleteMapping("deleteBatch")
    public R deleteBatch(@RequestParam("videoIdList") List<String> videoIdList) {
        return service.removeMoreAlyVideo(videoIdList);
    }



}
